namespace ConcurrentBoo.Tests

import System
import NUnit.Framework
import ConcurrentBoo

[TestFixture]
class FunctionalTestFixture:
	
	[Test]
	def TestCMap():
		elapsed = time() do:
			i = 0
			for originalItem, mappedItem in cmap(range(100), computation):
				Assert.AreEqual(i, originalItem)
				Assert.AreEqual(i*2, mappedItem)
				++i
			Assert.AreEqual(100, i)
				
		assert elapsed < 5s, "Total execution time must be less than sequential execution time"
		
	[Test]
	def TestCMapU():
		elapsed = time() do:
			i = 0
			for originalItem as int, mappedItem in cmapU(range(100), computation):
				Assert.AreEqual(originalItem*2, mappedItem)
				++i
			Assert.AreEqual(100, i)
		assert elapsed < 5s, "Total execution time must be less than sequential execution time"
		
	def time(action as callable()):
		started = date.Now
		action()
		return started-date.Now
			
	def computation(i as int):
		System.Threading.Thread.Sleep(50ms)
		return (i, i*2)
